<template>
  <Teleport to="body">
    <Transition name="modal-fade">
      <div v-if="show" class="confirm-modal-overlay" @click="handleCancel">
        <div class="confirm-modal" @click.stop>
          <!-- 装饰元素 -->
          <div class="decoration-top">
            <div class="star">⭐</div>
            <div class="star">✨</div>
            <div class="star">💫</div>
          </div>
          
          <!-- 图标 -->
          <div class="icon-wrapper">
            <div class="icon-circle"></div>
            <div class="question-icon">❓</div>
          </div>
          
          <!-- 标题 -->
          <h3 class="modal-title">{{ title }}</h3>
          
          <!-- 消息 -->
          <p class="modal-message">{{ message }}</p>
          
          <!-- 按钮组 -->
          <div class="button-group">
            <button class="btn-cancel" @click="handleCancel">
              <span>取消</span>
            </button>
            <button class="btn-confirm" @click="handleConfirm">
              <span>确定</span>
              <span class="btn-sparkle">✨</span>
            </button>
          </div>
          
          <!-- 底部装饰 -->
          <div class="decoration-bottom">
            <span class="heart">💗</span>
            <span class="heart">💖</span>
          </div>
        </div>
      </div>
    </Transition>
  </Teleport>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  },
  title: {
    type: String,
    default: '确认操作'
  },
  message: {
    type: String,
    default: '确定要执行此操作吗？'
  }
})

const emit = defineEmits(['update:modelValue', 'confirm', 'cancel'])

const show = ref(props.modelValue)

watch(() => props.modelValue, (newVal) => {
  show.value = newVal
})

const handleConfirm = () => {
  show.value = false
  emit('update:modelValue', false)
  emit('confirm')
}

const handleCancel = () => {
  show.value = false
  emit('update:modelValue', false)
  emit('cancel')
}
</script>

<style scoped>
.confirm-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.confirm-modal {
  position: relative;
  background: linear-gradient(135deg, #fff5f7 0%, #ffe4e8 100%);
  border-radius: 24px;
  padding: 40px 30px 30px;
  max-width: 420px;
  width: 100%;
  box-shadow: 
    0 20px 60px rgba(255, 105, 180, 0.4),
    0 0 0 1px rgba(255, 182, 193, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  animation: modalSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 装饰 */
.decoration-top {
  position: absolute;
  top: 15px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  pointer-events: none;
}

.star {
  font-size: 18px;
  animation: twinkle 2s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% {
    opacity: 0.3;
    transform: scale(0.8) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.2) rotate(180deg);
  }
}

/* 图标 */
.icon-wrapper {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
}

.icon-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #FFB6C1 0%, #FF69B4 100%);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 8px 25px rgba(255, 105, 180, 0.4);
}

@keyframes pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
  }
}

.question-icon {
  position: relative;
  z-index: 2;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* 标题 */
.modal-title {
  font-size: 22px;
  font-weight: 700;
  color: #FF1493;
  text-align: center;
  margin: 0 0 15px 0;
  text-shadow: 0 2px 4px rgba(255, 20, 147, 0.2);
}

/* 消息 */
.modal-message {
  font-size: 15px;
  color: #666;
  text-align: center;
  margin: 0 0 25px 0;
  line-height: 1.6;
  white-space: pre-line;
}

/* 按钮组 */
.button-group {
  display: flex;
  gap: 12px;
}

.btn-cancel,
.btn-confirm {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-cancel {
  background: white;
  color: #999;
  border: 2px solid #E0E0E0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-cancel:hover {
  border-color: #FFB6C1;
  color: #FF69B4;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 182, 193, 0.3);
}

.btn-confirm {
  background: linear-gradient(135deg, #FF69B4 0%, #FF1493 100%);
  color: white;
  box-shadow: 
    0 4px 15px rgba(255, 20, 147, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: hidden;
}

.btn-confirm::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.5s;
}

.btn-confirm:hover::before {
  left: 100%;
}

.btn-confirm:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 20, 147, 0.5);
}

.btn-cancel:active,
.btn-confirm:active {
  transform: translateY(0);
}

.btn-sparkle {
  display: inline-block;
  animation: sparkleRotate 2s linear infinite;
}

@keyframes sparkleRotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 底部装饰 */
.decoration-bottom {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 15px;
  pointer-events: none;
}

.heart {
  font-size: 16px;
  animation: float 3s ease-in-out infinite;
}

.heart:nth-child(1) {
  animation-delay: 0s;
}

.heart:nth-child(2) {
  animation-delay: 0.5s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

/* 过渡动画 */
.modal-fade-enter-active,
.modal-fade-leave-active {
  transition: opacity 0.3s ease;
}

.modal-fade-enter-from,
.modal-fade-leave-to {
  opacity: 0;
}

/* 响应式 */
@media (max-width: 480px) {
  .confirm-modal {
    padding: 30px 20px 25px;
  }
  
  .modal-title {
    font-size: 20px;
  }
  
  .button-group {
    flex-direction: column-reverse;
  }
}
</style>
